<?php
/**
 * @author spenceryg
 * @date 2022/1/30
 * @time 5:19 下午
 * @focus love & life
 */

namespace app\admin\controller\sys\validate;

use think\Validate;

class LoginValidate extends Validate
{
    protected $rule = [
        'username' => 'require',
        'password' => 'require',
        'captcha' => 'require|checkCaptcha'
    ];


    protected $message = [
        'username.require' => '用户名必须',
        'password.require' => '密码必须',
        'captcha.require' => '验证码必须',
    ];


    /**
     * 验证验证码是否正确
     * @param $value
     * @param $rule
     * @param $data
     * @return bool|string
     */
    protected function checkCaptcha($value, $rule, $data)
    {
        if (captcha_check($value)) {
            return true;
        } else {
//            session('captcha.key');
            return '验证码错误！';
        }
    }
}
